//
//  InviteFriendSuccessView.swift
//  SmartHousekeeper
//
//  Created by 张磊 on 2020/2/23.
//  Copyright © 2020 LS. All rights reserved.
//

import UIKit
//邀请客人成功
class InviteFriendSuccessView: UIView {
    typealias InviteFriendSuccessViewSendWXBlcok = () -> ()
    var sendWXBlcok : InviteFriendSuccessViewSendWXBlcok?  = nil
    
    typealias InviteFriendSuccessViewSendFriendBlcok = ()->()
    public var sendFriendBlcok : InviteFriendSuccessViewSendFriendBlcok? = nil
    
    typealias InviteFriendSuccessViewPopRootBlcok = ()->()
    public var popRootBlcok : InviteFriendSuccessViewPopRootBlcok? = nil
    
    let backGroudImg = UIImageView()
    
    
    lazy var imgLogo : UIImageView = {
        let value = UIImageView(image: UIImage(named: "icon_yqkr"))
        return value
    }()
    
    lazy var communityL : UILabel = {
        let value = UILabel(textColor: RGBColor(r: 40, g: 40, b: 40, a: 1), textFont: UIFont.boldSystemFont(ofSize: Adapter(20)))
        value.text = "邀请客人进入小区预约登记"
        return value
    }()
    
    lazy var imgLogoSuccess : UIImageView = {
        let value = UIImageView(image: UIImage(named: "icon_yqsuccess"))
        return value
    }()
    
    lazy var communitySuccessL : UILabel = {
        let value = UILabel(textColor: RGBColor(r: 62, g: 134, b: 230, a: 1), textFont: UIFont.boldSystemFont(ofSize: Adapter(22)))
        value.text = "预约成功"
        return value
    }()
    
    lazy var titleL : UILabel = {
        let value = UILabel(textColor: RGBColor(r: 162, g: 162, b: 162, a: 1), textFont: UIFont.boldSystemFont(ofSize: Adapter(17)))
        value.text = "唐先生将于2020年2月17日来您家做客"
        return value
    }()
    
    lazy var qrBgView : UIView = {
        let value = UIView()
        value.layer.borderColor = RGBColor(r: 114, g: 114, b: 114, a: 114).cgColor
        value.layer.borderWidth = 1
        return value
    }()
    
    lazy var qrImg : UIImageView = {
        let value = UIImageView()
        return value
    }()
    
    lazy var title2L : UILabel = {
        let value = UILabel(textColor: RGBColor(r: 162, g: 162, b: 162, a: 1), textFont: UIFont.boldSystemFont(ofSize: Adapter(17)))
        value.text = "您可以把一下预约二维码分享给好友"
        return value
    }()
    
    lazy var backBtn : UIButton = {
        let value = UIButton(textColor: RGBColor(r: 40, g: 40, b: 40, a: 1), textFont: UIFont.boldSystemFont(ofSize: Adapter(18)))
        value.setTitle("返回首页", for: .normal)
        value.setImage(UIImage(named: "back"), for: .normal)
        return value
    }()
    lazy var sendWXBtn : UIButton = {
        let value = UIButton(textColor:.white, textFont: UIFont.boldSystemFont(ofSize: Adapter(22)))
        value.setTitle("发微信", for: .normal)
        value.backgroundColor = RGBColor(r: 40, g: 153, b: 57, a: 1)
        value.layer.cornerRadius = Adapter(5)
        value.layer.masksToBounds = true
        return value
    }()
    lazy var sendFriendBtn : UIButton = {
        let value = UIButton(textColor: .white, textFont: UIFont.boldSystemFont(ofSize: Adapter(22)))
        value.setTitle("发给朋友", for: .normal)
        value.backgroundColor = RGBColor(r: 45, g: 98, b: 168, a: 1)
        value.layer.cornerRadius = Adapter(5)
        value.layer.masksToBounds = true
        return value
    }()
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUi()
    }
    private func setUi(){
        
        backGroudImg.image = UIImage(named: "mianBack")
        self .addSubview(backGroudImg)
        backGroudImg.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        let top : CGFloat = UIDevice.isX() ? 88 : 64
        
        self.addSubview(communityL)
        communityL.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview().offset(Adapter(15))
            make.top.equalToSuperview().offset(top)
            make.height.equalTo(Adapter(20))
        }
        
        self.addSubview(imgLogo)
        imgLogo.snp.makeConstraints { (make) in
            make.right.equalTo(communityL.snp.left).offset(-Adapter(10))
            make.centerY.equalTo(communityL)
            make.size.equalTo(CGSize(width: Adapter(20), height: Adapter(20)))
        }
        
        
        
        let line = UIView()
        line.backgroundColor = RGBColor(r: 114, g: 114, b: 114, a: 1)
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(Adapter(15))
            make.right.equalTo(self).offset(-Adapter(15))
            make.top.equalTo(communityL.snp.bottom).offset(Adapter(44))
            make.height.equalTo(Adapter(0.8))
        }
        
        self.addSubview(communitySuccessL)
        communitySuccessL.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview().offset(Adapter(15))
            make.top.equalTo(line.snp.bottom).offset(Adapter(35))
            make.height.equalTo(Adapter(24))
        }
        
        self.addSubview(imgLogoSuccess)
        imgLogoSuccess.snp.makeConstraints { (make) in
            make.right.equalTo(communitySuccessL.snp.left).offset(-Adapter(10))
            make.size.equalTo(CGSize(width: Adapter(20), height: Adapter(20)))
            make.centerY.equalTo(communitySuccessL)
        }
        
        self.addSubview(titleL)
        titleL.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(communitySuccessL.snp.bottom).offset(Adapter(35))
            make.height.equalTo(Adapter(20))
        }
        
        self.addSubview(qrBgView)
        qrBgView.snp.makeConstraints { (make) in
            make.top.equalTo(titleL.snp.bottom).offset(Adapter(35))
            make.size.equalTo(CGSize(width:(ScreenWidth - Adapter(190)), height: (ScreenWidth - Adapter(190))))
            make.centerX.equalToSuperview()
        }
        
        
        
        
        qrImg.image = UIImage.cwQRCodeImage(content: "333333333")
        
        self.addSubview(qrImg)
        qrImg.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width:(ScreenWidth - Adapter(215)), height: (ScreenWidth - Adapter(220))))
            make.center.equalTo(qrBgView)
        }
        
        self.addSubview(title2L)
        title2L.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(qrImg.snp.bottom).offset(Adapter(35))
            make.height.equalTo(Adapter(20))
        }
        
        self.addSubview(backBtn)
        backBtn.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(title2L.snp.bottom).offset(Adapter(35))
            make.size.equalTo(CGSize(width: Adapter(200), height: Adapter(25)))
        }
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
            self.backBtn.imagePosition(at: .left, space: Adapter(10))
        }
        
        let company = UILabel()
        company.textColor = RGBColor(r: 116, g: 116, b: 116, a: 1)
        company.font = UIFont.systemFont(ofSize: Adapter(12))
        company.text = "技术提供商:上海领美软件科技有限公司"
        self.addSubview(company)
        self.addSubview(sendWXBtn)
        self.addSubview(sendFriendBtn)
        
        
        let width : CGFloat = (ScreenWidth - Adapter(70)) / 2
        
        if UIDevice.isX() {
            
            
            sendWXBtn.snp.makeConstraints { (make) in
                make.bottom.equalToSuperview().offset(-Adapter(45))
                make.left.equalToSuperview().offset(Adapter(30))
                make.size.equalTo(CGSize(width: width, height: Adapter(55)))
            }
            
            sendFriendBtn.snp.makeConstraints { (make) in
                make.top.equalTo(sendWXBtn)
                make.right.equalToSuperview().offset(-Adapter(30))
                make.size.equalTo(CGSize(width: width, height: Adapter(55)))
            }
            company.snp.makeConstraints { (make) in
                make.centerX.equalToSuperview()
                make.bottom.equalTo(sendWXBtn.snp.top).offset(-Adapter(15))
                make.height.equalTo(Adapter(20))
            }
            
            
        } else {
            
            company.snp.makeConstraints { (make) in
                make.centerX.equalToSuperview()
                make.top.equalTo(backBtn.snp.bottom).offset(Adapter(Adapter(35)))
                make.height.equalTo(Adapter(20))
            }
            
            
            sendWXBtn.snp.makeConstraints { (make) in
                make.top.equalTo(company.snp.bottom).offset(Adapter(15))
                make.left.equalToSuperview().offset(Adapter(30))
                make.size.equalTo(CGSize(width: width, height: Adapter(55)))
            }
            
            sendFriendBtn.snp.makeConstraints { (make) in
                make.top.equalTo(company.snp.bottom).offset(Adapter(15))
                make.right.equalToSuperview().offset(-Adapter(30))
                make.size.equalTo(CGSize(width: width, height: Adapter(55)))
            }
            
            
        }
        
        sendFriendBtn.sce.add(.touchUpInside) { (btn) in
            self.sendFriendBlcok?()
        }
        sendWXBtn.sce.add(.touchUpInside) { (btn) in
            self.sendWXBlcok?()
        }
        backBtn.sce.add(.touchUpInside) { (btn) in
            self.popRootBlcok?()
        }
        
        
    }
    
}
